<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\plat\logic;

/**
 * 登录逻辑
 */
class Reg extends PlatBase
{
    /**
     * 注册
     */
    public function regPlatUser($data = [])
    {
        $validate_result = $this->validateReg->scene('reg')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $this->validateReg->getError()];
        }
        $this->modelTenUser->setIgnoreTenantCheck();
        $tenUserInfo = $this->modelTenUser->getInfo(['username' => $data['username']]);
        if ($tenUserInfo) {
            throw_response_error('帐号已经被注册了');
        } else {
            $tenUserData = [
                'username' => $data['username'],
                'password' => data_md5_key($data['password']),
                'ten_tenant_id' => 0,//默认注册为普通用户
            ];
            $this->modelTenUser->setIgnoreTenantCheck();
            $tenUserId = $this->modelTenUser->setInfo($tenUserData);
            $url = url('Login/login');
            return $tenUserId ? [RESULT_SUCCESS, '注册成功', $url] : [RESULT_ERROR, $this->modelSysAuthAccess->getError()];
        }
    }
}